#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    int maximumBeauty(vector<int>& nums, int k) {
        int res = 0;
        sort(nums.begin(), nums.end());
        int left = 0;
        for (int right = 0; right < nums.size(); ++right) {
            while (nums[right] - nums[left] > 2 * k) {
                ++left;
            }
            res = max(res, right - left + 1);
        }
        return res;
    }
};

int main() {
    Solution s;

    vector<int> nums1 = {4, 6, 1, 2};
    vector<int> nums2 = {1, 1, 1, 1};

    int k1 = 2;
    int k2 = 10;

    assert(s.maximumBeauty(nums1, k1) == 3);
    assert(s.maximumBeauty(nums2, k2) == 4);

    return 0;
}